package com.tengfei.gulishop.product.controller;

import java.util.Arrays;
import java.util.Map;

import javax.annotation.Resource;

import com.tengfei.gulishop.product.vo.AttrGroupRelationVo;
import com.tengfei.gulishop.product.vo.AttrRespVo;
import com.tengfei.gulishop.product.vo.AttrVo;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tengfei.gulishop.product.entity.AttrEntity;
import com.tengfei.gulishop.product.service.AttrService;
import com.tengfei.common.utils.PageUtils;
import com.tengfei.common.utils.R;


/**
 * 商品属性
 *
 * @author feige
 * @email ourfeige@gmail.com
 * @date 2022-07-13 17:37:26
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Resource
    private AttrService attrService;


    /**
     * 销售属性列表
     */
    @RequestMapping("/sale/list/{catelogId}")
    //@RequiresPermissions("product:attr:list")
    public R<PageUtils> saleAttrList(@RequestParam Map<String, Object> params, @PathVariable("catelogId") Long catelogId) {
        PageUtils page = attrService.querySaleAttrPage(params, catelogId);

        return R.ok(page);
    }

    /**
     * 规格参数列表
     */
    @RequestMapping("/base/list/{catelogId}")
    //@RequiresPermissions("product:attr:list")
    public R<PageUtils> baseAttrList(@RequestParam Map<String, Object> params, @PathVariable("catelogId") Long catelogId) {
        PageUtils page = attrService.queryBaseAttrPage(params, catelogId);

        return R.ok(page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:attr:list")
    public R<PageUtils> list(@RequestParam Map<String, Object> params) {
        PageUtils page = attrService.queryPage(params);

        return R.ok(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    //@RequiresPermissions("product:attr:info")
    public R<AttrRespVo> info(@PathVariable("attrId") Long attrId) {
        AttrRespVo attrRespVo = attrService.getAttrInfo(attrId);
        return R.ok(attrRespVo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:attr:save")
    public R save(@RequestBody AttrVo attr) {
        attrService.saveAttr(attr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:attr:update")
    public R update(@RequestBody AttrVo attr) {
        attrService.updateAttr(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:attr:delete")
    public R delete(@RequestBody Long[] attrIds) {
        attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }


}
